#include "dma1.h"
#include "stdio.h"
#include "string.h"
#include "uart1.h"



DMA_HandleTypeDef dma1_handle = {0};

//uint32_t src_buf[MAX_LEN] = {0X11111111, 0X22222222, 0X33333333, 0X44444444, 0X55555555};
//uint32_t dst_buf[MAX_LEN] = {0};
    
void dma1_init(void)
{
    __HAL_RCC_DMA1_CLK_ENABLE();
    
    dma1_handle.Instance = DMA1_Channel5;
    dma1_handle.Init.Direction = DMA_PERIPH_TO_MEMORY;
    dma1_handle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
    dma1_handle.Init.MemInc = DMA_MINC_ENABLE;
    dma1_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    dma1_handle.Init.PeriphInc = DMA_PINC_DISABLE;
    dma1_handle.Init.Priority = DMA_PRIORITY_MEDIUM;
    dma1_handle.Init.Mode = DMA_NORMAL;
    
    HAL_DMA_Init(&dma1_handle);
    __HAL_LINKDMA(&uart1_handle, hdmarx, dma1_handle);
    HAL_UART_Receive_DMA(&uart1_handle, uart1_rx_buf, UART1_RX_BUF_SIZE);
}

//void dma1_transmit(void)
//{
//    HAL_DMA_Start_IT(&dma1_handle, (uint32_t)src_buf, (uint32_t)dst_buf, sizeof(uint32_t) * MAX_LEN);
//    while (__HAL_DMA_GET_FLAG(&dma1_handle, DMA_FLAG_TC2) == RESET);
//    
//    for (int i = 0; i < MAX_LEN; i++)
//    {
//        printf("dst %d element = %X \r\n", i, dst_buf[i]);
//    }
//    
//    memset(dst_buf, 0, sizeof dst_buf);
//}
